#!/bin/bash

# kCloud Frontend Build Script

echo "🚀 Starting kCloud Frontend Build..."

# 检查Node.js版本
echo "📋 Checking Node.js version..."
node --version
npm --version

# 清理之前的构建
echo "🧹 Cleaning previous build..."
rm -rf dist/

# 安装依赖
echo "📦 Installing dependencies..."
npm ci

# 类型检查
echo "🔍 Type checking..."
npm run type-check

# 构建生产版本
echo "🏗️ Building for production..."
npm run build

# 检查构建结果
if [ -d "dist" ]; then
    echo "✅ Build completed successfully!"
    echo "📊 Build statistics:"
    du -sh dist/
    find dist/ -name "*.js" -o -name "*.css" -o -name "*.html" | wc -l | xargs echo "Files generated:"
else
    echo "❌ Build failed!"
    exit 1
fi

echo "🎉 kCloud Frontend build process completed!"
